package com.ruoyi.monitormanage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.monitormanage.domain.TTestpointanddept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.monitormanage.domain.TTestpoint;
import com.ruoyi.monitormanage.service.ITTestpointService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * monitormanagebuildController
 *
 * @author xiaodabao
 * @date 2025-06-06
 */
@RestController
@RequestMapping("/testpoint")
public class TTestpointController extends BaseController
{
    @Autowired
    private ITTestpointService tTestpointService;

    /**
     * 查询monitormanagebuild列表
     */
    @RequiresPermissions("monitormanage:testpoint:list")
    @GetMapping("/list")
    public TableDataInfo list(TTestpoint tTestpoint)
    {
        startPage();
        List<TTestpointanddept> list = tTestpointService.selectTTestpointList(tTestpoint);
        return getDataTable(list);
    }

    /**
     * 导出monitormanagebuild列表
     */
    @RequiresPermissions("monitormanage:testpoint:export")
    @Log(title = "monitormanagebuild", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TTestpoint tTestpoint)
    {
        List<TTestpointanddept> list = tTestpointService.selectTTestpointList(tTestpoint);
        ExcelUtil<TTestpointanddept> util = new ExcelUtil<TTestpointanddept>(TTestpointanddept.class);
        util.exportExcel(response, list, "monitormanagebuild数据");
    }

    /**
     * 获取monitormanagebuild详细信息
     */
    @RequiresPermissions("monitormanage:testpoint:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tTestpointService.selectTTestpointById(id));
    }

    /**
     * 新增monitormanagebuild
     */
    @RequiresPermissions("monitormanage:testpoint:add")
    @Log(title = "monitormanagebuild", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TTestpoint tTestpoint)
    {
        if (!tTestpointService.checkTestpointUnique(tTestpoint))
        {
            return error("新增监测点失败，该监测点已存在");
        }
        return toAjax(tTestpointService.insertTTestpoint(tTestpoint));
    }

    /**
     * 修改monitormanagebuild
     */
    @RequiresPermissions("monitormanage:testpoint:edit")
    @Log(title = "monitormanagebuild", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TTestpoint tTestpoint)
    {
        return toAjax(tTestpointService.updateTTestpoint(tTestpoint));
    }

    /**
     * 删除monitormanagebuild
     */
    @RequiresPermissions("monitormanage:testpoint:remove")
    @Log(title = "monitormanagebuild", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tTestpointService.deleteTTestpointByIds(ids));
    }

    /**
     * 导入上一年度监测点
     */
    @RequiresPermissions("monitormanage:testpoint:import")
    @Log(title = "monitormanagebuild", businessType = BusinessType.IMPORT)
    @PostMapping("/import")
    public AjaxResult importtestpoints(@RequestBody TTestpoint tTestpoint)
    {
        return toAjax(tTestpointService.importtestpoints(tTestpoint));
    }
    /**
     * 查询监测点年份列表
     */
    @PostMapping("/getyears")
    public List<String> selectyearlist(TTestpoint tTestpoint)
    {
        return tTestpointService.selectyearlist(tTestpoint);
    }
}
